<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="问题" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="questionId">
              <!-- <j-dict-select-tag
                disabled
                type="list"
                v-model="model.questionId"
                dictCode="ht_forums_question,name,id"
                placeholder="请选择问题ID"
              /> -->
              <!-- <a-input disabled v-model="model.name"> </a-input> -->
              <p>{{ model.name }}</p>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="问题描述" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="description">
              <!-- <j-editor v-model="model.description" /> -->
              <!-- <textarea v-model="model.description"></textarea> -->
              <div v-html="model.description"></div>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="回答内容" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="content">
              <j-editor v-model="model.content" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'

export default {
  name: 'HTExpertAnswerForm',
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      model: {
        auditStatus: 0
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      validatorRules: {
        content: [{ required: true, message: '请输入回答内容' }]
      },
      url: {
        expertRelpy: '/forums/hTForumsAnswer/expert/reply'
      }
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    }
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    add() {
      this.edit(this.modelDefault)
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.visible = true
    },
    submitForm() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          console.log('\n\n valid:' + JSON.stringify(valid) + '\n\n')
          that.confirmLoading = true
          const parameters = {
            ...that.model,
            questionId: that.model.id
          }

          httpAction(that.url.expertRelpy, parameters, 'post')
            .then(res => {
              console.log('\n\n res :' + JSON.stringify(res) + '\n\n')
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
            })
        }
      })
    }
  }
}
</script>

